package it.antonio.ilpizze.db.security;

import static it.antonio.ilpizze.db.security.Operation.*;

public enum Role {
	ADMIN(ADMINISTRATION, WRITE, READ), 
	READ_ONLY(READ),
	READ_AND_WRITE(WRITE, READ),
	UNAUTHORIZED();
	
	private Operation[] operations;
	private boolean canWrite = false;
	private boolean canRead = false;
	private boolean isAdmin = false;
	
	private Role(Operation... ops) {
		for(Operation op: ops) {
			if(op == WRITE) canWrite = true;
			if(op == READ) canRead = true; 
			if(op == ADMINISTRATION) isAdmin = true; 
		}
	}
	
	public boolean allowed(Operation operation) {
		for (Operation op : operations) {
			if (op == operation) {
				return true;
			}
		}
		return false;
	}

	public final boolean isAdmin(){
		return isAdmin;
	}
	public final boolean canRead(){
		return canRead;
	}
	public final boolean canWrite(){
		return canWrite;
	}
}
